
// <copyright file="CounterUpdateInfo.cs" company="Subhadra Software Solutions">
//   
// </copyright>
// <summary>
//   The counter update info.
// </summary>

namespace SubhadraSolutions.Sharp.Utils.Diagnostics.Performance.Dtos
{
    using System;
    using System.Collections.Generic;

    /// <summary>
    /// The counter update info.
    /// </summary>
    [Serializable]
    public class CounterUpdateInfo
    {
        #region Constructors and Finalizers

        /// <summary>
        /// Initializes a new instance of the <see cref="CounterUpdateInfo"/> class.
        /// </summary>
        public CounterUpdateInfo()
        {
            this.ProcessInfo = new ProcessInfo();
            this.Categories = new List<CounterCategoryInfo>();
        }

        #endregion Constructors and Finalizers

        #region Public Properties

        /// <summary>
        /// Gets or sets the categories.
        /// </summary>
        public List<CounterCategoryInfo> Categories { get; set; }

        /// <summary>
        /// Gets or sets the process info.
        /// </summary>
        public ProcessInfo ProcessInfo { get; set; }

        #endregion Public Properties

        #region Public Methods and Operators

        /// <summary>
        /// The get category info.
        /// </summary>
        /// <param name="categoryName">
        /// The category name.
        /// </param>
        /// <param name="ignoreCase">
        /// The ignore case.
        /// </param>
        /// <returns>
        /// The <see cref="CounterCategoryInfo"/>.
        /// </returns>
        public CounterCategoryInfo GetCategoryInfo(string categoryName, bool ignoreCase)
        {
            foreach (CounterCategoryInfo categoryInfo in this.Categories)
            {
                if (string.Compare(categoryInfo.CategoryName, categoryName, ignoreCase) == 0)
                {
                    return categoryInfo;
                }
            }

            return null;
        }

        /// <summary>
        /// The get counter value.
        /// </summary>
        /// <param name="categoryName">
        /// The category name.
        /// </param>
        /// <param name="instanceName">
        /// The instance name.
        /// </param>
        /// <param name="counterName">
        /// The counter name.
        /// </param>
        /// <param name="ignoreCase">
        /// The ignore case.
        /// </param>
        /// <returns>
        /// The <see cref="double?"/>.
        /// </returns>
        public double? GetCounterValue(string categoryName, string instanceName, string counterName, bool ignoreCase)
        {
            CounterCategoryInfo category = this.GetCategoryInfo(categoryName, ignoreCase);
            if (category != null)
            {
                return category.GetCounterValue(instanceName, counterName, ignoreCase);
            }

            return null;
        }

        #endregion Public Methods and Operators
    }
}
